<!DOCTYPE html>
<html>
  <head>
    <title>物流公司管理</title>
    <include file='public/head'>
    <style>
        .layui-legend-size{font-size:14px !important;}
        .layui-nopadding{padding:0 !important;}
        .layui-overflow{overflow:auto;}
        .layui-nomargin{margin: 0 !important;}
        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
        .layui-input{height:30px !important; }
        .layui-form-search-item .layui-inline{margin-bottom: 5px;} 
        .layui-form-search-item label{margin-left: 15px;}
        .layui-table-page {padding: 7px 0px 0px;}
        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
    </style>
</head>
<body>
  <!-- layui-tab开始 -->
  <div class="layui-tab" lay-fliter="demo-tab">
    <!-- 顶部导航菜单开始 -->
    <div class="layui-tab-nav">
      <ul class="layui-tab-title">
          {:getNav('logistics','admin_index/index')};
      </ul>
    </div>
    <!-- 顶部导航菜单结束 -->
    <br>
      
    <!-- 内容开始 -->
    <div class="layui-card">
        
        <!-- 表头按钮开始 -->
        <div class="layui-card-header layui-bg-gray layui-bottom">
            <a href="javascript:;" class="layui-btn layui-btn-xs add-btn" >添加快递公司</a>
            <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger delete-btn" >批量删除</a>
        </div>
        <!-- 表头按钮结束 -->
    
    <!-- 数据表格开始 -->
    <form method="post" id="f">
    <table class="layui-table layui-nomargin">
        <thead>
            <tr>
                <th rowspan="2" style="text-align:center; width: 20px;">
                    <input type="checkbox"  id="check-box-all" >
                </th>
                <th>ID</th>
                <th>物流公司</th>
                <th>公司编码</th>
                <th>操作</th>
            </tr>
            
        </thead>
        <tbody>
            <volist  name="data" id="vo">
                <tr lay-fliter="test3">
                    <th style="text-align:center;">
                        <input type="checkbox" class="check-box " name="id[]" value="{$vo['id']}">
                    </th>
                    <td>{$vo.id}</td>
                    <td>{$vo.company}</td>
                    <td>{$vo.code}</td>
                    <td>
                        <div class="layui-btn-group">
                        <button type="button" onclick="edit({$vo.id})"class="layui-btn layui-btn-primary layui-btn-xs" title="编辑"><i class="layui-icon">&#xe642;</i></button>
                        <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" title="删除"><i class="layui-icon">&#xe640;</i></button>
                        </div>
                    </td>
                </tr>
            </volist>
        </tbody>
    </table>


    <!--分页开始-->
    <div class="layui-table-page">
        <div id="layui-table-page1">
            <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
                {$page|default=''}
            </div>
        </div>
    </div>
    <!-- 分页结束 -->

    </form>
    <!-- 数据表格结束 -->
    </div>
    <!-- 内容结束 -->
    
  </div>
  <!-- layui-tab开始 -->
</body>

<include file="public/scripts"/>
<script>
  //全选/取消
  $('#check-box-all').on('click',function(){	
    console.log(1111);
    $('.check-box').prop('checked',$('#check-box-all').prop('checked'));

    console.log($('#check-box-all').prop('checked'));
  }); 

/**
 * 编辑
 */
function edit(id)
{
    layer.open({
        title:'修改信息',
        type: 2,
		shadeClose: true,//是否点击遮罩关闭
        btn:["确定","取消"],
        area: ['500px','300px'],
        content: "{:cmf_plugin_url('Logistics://admin_index/editPage')}?id="+id,
        yes:function(index,layero){
           //子页面的请求操作都放子页面
           var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.tijiao();
        },btn2:function(index, layero){
			}
    })
}


/**
 * 添加
 */
 $('.add-btn').on('click',function (){
    layer.open({
        title:'添加快递公司',
        type: 2,
		shadeClose: true,//是否点击遮罩关闭
        btn:["确定","取消"],
        area: ['500px','300px'],
        content: "{:cmf_plugin_url('Logistics://admin_index/addPage')}",
        yes:function(index,layero){
          //子页面的请求操作都放子页面
          var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
            iframeWin.tijiao();
        }
    })
})

/**
 * 删除
 */
 $('.delete-btn').on('click',function(){
        var id_str = $('input[type=checkbox]:checked').map(function(){return this.value}).get().join(',');
        let id = $(this).data('id');
        if(id == undefined) id = id_str;
        //询问
        layer.confirm('确定要删除吗？',{icon:3,title:'提示',btn:['删除','取消']}
        ,function(index,layero){
            $.ajax({
                url:"{:cmf_plugin_url('Logistics://admin_index/delete')}",
                type:'post',
                data:{id:id},
                success:function(data){
                    let icon = ( data.code == 200 ) ? 1 : 5 ;
                    layer.msg( data.message , { time:1200 , icon:icon },function(){
                        window.location.reload();
                    });
                },
                error:function(data){
                    console.log(data);
                    layer.msg('系统错误',{time:1200,icon:5});
                }
            })   
        },function(index){});
       
    })

</script>
</html>